<?php

/**
 * \file
 * Classe `Address`.
 */

namespace pilar\SimpleFormMembers /* \cond */ ; /* \endcond */
{

/**
 * Membre d'adresse postale.
 *
 * \since 03/02/2009
 * \author Olivier LEMASLE <o.lemasle@gmail.com>
 */
class Address extends \pilar\Forms\Member {

protected function initialize() {
 parent::initialize();
 
 $this->joinField('line1');	
 $this->joinField('line2');
 $this->joinField('zipCode');
 $this->joinField('city');
 $this->joinField('country');
}


public function guiDomNode($domDoc) {
 $domGui = $domDoc->createElement('gui');

 $domLine1 = $domDoc->createElement('input');
 $domLine1->setAttribute('id', $this->globalId('line1'));
 $domLine1->setAttribute('name', $this->globalId('line1'));
 $domLine1->setAttribute('size', 40);
 $domLine1->setAttribute('maxlength', 80);
 $domLine1->setAttribute('title', $this->get('label').' (ligne 1)');
 $domDiv = $domDoc->createElement('div');
 $domDiv->appendChild($domLine1);
 $domGui->appendChild($domDiv);
 
 $domLine2 = $domDoc->createElement('input');
 $domLine2->setAttribute('id', $this->globalId('line2'));
 $domLine2->setAttribute('name', $this->globalId('line2'));
 $domLine2->setAttribute('size', 40);
 $domLine2->setAttribute('maxlength', 80);
 $domLine2->setAttribute('title', $this->get('label').' (ligne 2)');
 $domDiv = $domDoc->createElement('div');
 $domDiv->appendChild($domLine2);
 $domGui->appendChild($domDiv);
  
 $domZipCode = $domDoc->createElement('input');
 $domZipCode->setAttribute('id', $this->globalId('zipCode'));
 $domZipCode->setAttribute('name', $this->globalId('zipCode'));
 $domZipCode->setAttribute('size', 6);
 $domZipCode->setAttribute('maxlength', 10);
 $domZipCode->setAttribute('title', $this->get('label').' (code postal)');
 $domDiv = $domDoc->createElement('div');
 $domDiv->appendChild($domDoc->createTextNode('Code postal : '));
 $domDiv->appendChild($domZipCode);
 $domGui->appendChild($domDiv);
 
 $domCity = $domDoc->createElement('input');
 $domCity->setAttribute('id', $this->globalId('city'));
 $domCity->setAttribute('name', $this->globalId('city'));
 $domCity->setAttribute('size', 20);
 $domCity->setAttribute('maxlength', 50);
 $domCity->setAttribute('title', $this->get('label').' (ville)');
 $domDiv = $domDoc->createElement('div');
 $domDiv->appendChild($domDoc->createTextNode('Ville : '));
 $domDiv->appendChild($domCity);
 $domGui->appendChild($domDiv);
  
 $domCountry = $domDoc->createElement('input');
 $domCountry->setAttribute('id', $this->globalId('country'));
 $domCountry->setAttribute('name', $this->globalId('country'));
 $domCountry->setAttribute('size', 20);
 $domCountry->setAttribute('maxlength', 60);
 $domCountry->setAttribute('title', $this->get('label').' (pays)');
 $domDiv = $domDoc->createElement('div');
 $domDiv->appendChild($domDoc->createTextNode('Pays : '));
 $domDiv->appendChild($domCountry);
 $domGui->appendChild($domDiv);

 return $domGui;
}


public function outputGuiController() { ?>
<?php foreach($this->fieldNames() as $f) { ?>
<?php  if($this->value($f) != '') { ?>
$('#<?php echo $this->globalId($f) ?>').val('<?php echo $this->value($f) ?>');
<?php  } ?>
<?php  if($this->status() == 'invalid') { ?>
$('#<?php echo $this->globalId($f) ?>').addClass('invalid');
<?php  } ?>
<?php } ?>
<?php
}

} // Class.

} // Namespace.

?>
